package cate.game.pvp.throne.data.ko;

import cate.common.table.activity.throne.TBKoRoundRow;
import cate.common.table.d.GDThrone;
import cate.common.util.TimeTool;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@NoteClass("王座争霸-轮次时间表")
@Slf4j
public class TBKoRoundTime {

	@NoteField("回合")
	public int round;

	@NoteField("每个阶段具体的开始时间")
	public Map<Integer,Long> timeMap = new HashMap<>();

	@JsonIgnore
	public long getTime(int period) {
		return timeMap.getOrDefault(period, 0L);
	}

	public TBKoRoundTime(int round) {
		this.round = round;
	}

	public TBKoRoundTime() {
	}


	/**
	 * 构建回合时间
	 * @param roundStartTime 回合开始时间
	 * @param row
	 */
	public void buildTime(long roundStartTime, TBKoRoundRow row) {
		timeMap.put(GDThrone.KoPeriod.BET, roundStartTime);
		roundStartTime += row.betTime;
		timeMap.put(GDThrone.KoPeriod.FIGHT, roundStartTime);
		roundStartTime += row.fightTime;
		timeMap.put(GDThrone.KoPeriod.REST, roundStartTime);
		long betTime = this.timeMap.get(GDThrone.KoPeriod.BET);
		//计算时间在竞猜开始10秒后
		long calTime = betTime + TimeTool.TimeCons.SECOND * 10;
		this.timeMap.put(GDThrone.KoPeriod.CAL, calTime);
		print();
	}

	public void print() {
		StringBuilder sb = new StringBuilder();
		sb.append("[王座争霸]-淘汰赛第[").append(round).append("]轮时间生成完毕");
		sb.append(" 竞猜：").append(TimeTool.getDF2().format(new Date(timeMap.get(GDThrone.KoPeriod.BET))));
		sb.append(" 计算：").append(TimeTool.getDF2().format(new Date(timeMap.get(GDThrone.KoPeriod.CAL))));
		sb.append(" 战斗：").append(TimeTool.getDF2().format(new Date(timeMap.get(GDThrone.KoPeriod.FIGHT))));
		sb.append(" 休息：").append(TimeTool.getDF2().format(new Date(timeMap.get(GDThrone.KoPeriod.REST))));
		log.info(sb.toString());
	}

}
